/**
 * @file src/datatypes/Node.java
 */
package datatypes;

/**
 * Class that represents a state
 */
public class Node implements Comparable<Node> 
{
    /** String representation of the state this node corresponds to*/
    private final String mState;
    
	/** Path costs up to this node */
	private float mPathCost;
	
	/** Cost function F() up to this node (needed for informed search) */
	private float mF;
	
	/** Hide default constructor */
	@SuppressWarnings("unused")
	private Node()
	{
		mState = null;
	}
	
	/**
	 * Constructor for Node 
	 * 
	 * @param state String representation of the state this node corresponds to
	 */
	public Node(String state)
	{
		mState = state;
		reset();
	}

	/**
	 * Copy constructor
	 */
	public Node(Node sourceNode)
	{
		mState = sourceNode.mState;
		mPathCost = sourceNode.mPathCost;
		mF = sourceNode.mF;
	}

	/**
	 * Reset a Node's internal state parameters
	 */
	public void reset()
	{
        mPathCost = Float.MAX_VALUE;
        mF = Float.MAX_VALUE;
	}
	
	/** Getter and setter */
	public String getState() 	{ return mState; }
	public float getPathCost() 	{ return mPathCost; }
	public float getF() 		{ return mF; }
	public void setPathCost(float pathCost) { mPathCost = pathCost; }
	public void setF(float f) 				{ mF = f; }

	/**
	 * Override toString()
	 * 
	 * @return String representation of this node
	 */
	public String toString() { return "In(" + mState + ")"; /* return mState; */}

	/**
	 * Override compareTo()
	 * 
	 * @param other Other node to compare to
	 * 
	 * @return -1 0 or 1 depending on comparison
	 */
	@Override
	public int compareTo(Node other)
	{
		if (mF < other.getF()) {
			return -1;
		} else if (mF > other.getF()) {
			return 1;
		}
		return 0;
	}

} // class Node
